/*
 * Copyright (C) 2017 The MoonLake Authors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


package com.minecraft.moonlake.legendaryweaponrel.weapons.bow;

import org.bukkit.Material;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;

public class HealBow extends WeaponAbstractBowBase {

    public HealBow() {
        super("healbow", "&b治疗弓", Material.BOW);
    }

    @Override
    public String[] getLore() {
        return new String[] {
                "&7被此弓射中的玩家将会给予 &c3❤ &7血量",
                "&7需要射箭时背包存在金锭 &8(&7消费&a1&7个&8)"
        };
    }

    @Override
    protected void onBowShoot(EntityShootBowEvent event, Player player, Arrow arrow) {
        // 处理弓射箭
        if(player.getInventory().first(Material.GOLD_INGOT) == -1) return; // 为 -1 说明背包不存在金锭则不设置属性

        // 清除玩家背包一个金锭然后设置弓箭属性
        player.getInventory().removeItem(new ItemStack(Material.GOLD_INGOT, 1));
        arrow.setMetadata(type, new FixedMetadataValue(getInstance(), (byte) 1));
    }

    @Override
    protected void onDamage(EntityDamageByEntityEvent event, Arrow arrow, Entity source) {
        // 处理弓箭伤害
        if(!arrow.hasMetadata(type)) return; // 没有属性值则说明非
        if(!(source instanceof Player)) return; // 受伤者不为玩家则返回

        healthPlayer(((Player) source), 6); // 恢复玩家的 6 生命也就是 3❤
    }
}
